/** 
 * Project Name:kaka 
 * File Name:HomeServiceImpl.java 
 * Package Name:com.luoran.kaka.service.impl 
 * Date:2018年12月19日下午4:16:48 
 * Copyright (c) 2018, Luoran, Inc. All Rights Reserved.
 * 
 */
package com.luoran.kaka.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.luoran.kaka.api.wechat.model.CardInfoVo;
import com.luoran.kaka.dao.IBasicInfoDao;
import com.luoran.kaka.dao.ICompanyDao;
import com.luoran.kaka.dao.IPicInfoDao;
import com.luoran.kaka.entity.BasicInfo;
import com.luoran.kaka.entity.CompanyInfo;
import com.luoran.kaka.entity.PicInfo;
import com.luoran.kaka.service.IHomeService;

/** 
 * @author ghl 
 * @since JDK 1.8
 * ClassName: HomeServiceImpl
 * date: 2018年12月19日 下午4:16:48
 *	
 */
@Service
public class HomeServiceImpl implements IHomeService {

	@Autowired
	private IBasicInfoDao basicInfoDao;

	@Autowired
	private ICompanyDao companyDao;

	@Autowired
	private IPicInfoDao picInfoDao;

	/** 
	 * @param condition
	 * @return
	 * @author ghl 2018年12月19日下午6:39:56
	 * queryAllPublicCard:
	 */
	@Override
	public List<CardInfoVo> queryAllPublicCard(String condition) {
		List<CardInfoVo> list = new ArrayList<>();
		List<BasicInfo> personalCards = basicInfoDao.getAllPublicPersonalCard(condition);
		List<CompanyInfo> companyCards = companyDao.getAllPublicCompanyCard(condition);
		// 封装个人名片
		if (personalCards != null && personalCards.size() > 0) {
			for (BasicInfo info : personalCards) {
				CardInfoVo cardInfoVo = new CardInfoVo();
				cardInfoVo.setId(info.getId());
				cardInfoVo.setName(info.getUserName());
				cardInfoVo.setDescription(info.getPersonalDesc());
				cardInfoVo.setType(1);
				if (!StringUtils.isEmpty(info.getPicId())) {
					PicInfo picInfo = picInfoDao.single(info.getPicId());
					if (picInfo != null) {
						cardInfoVo.setPicUrl(picInfo.getUrl());
					}
				}
				list.add(cardInfoVo);
			}
		}
		// 封装企业名片
		if (companyCards != null && companyCards.size() > 0) {
			for (CompanyInfo companyInfo : companyCards) {
				CardInfoVo cardInfoVo = new CardInfoVo();
				cardInfoVo.setId(companyInfo.getId());
				cardInfoVo.setName(companyInfo.getCompanyName());
				cardInfoVo.setDescription(companyInfo.getCompanyDesc());
				cardInfoVo.setType(2);
				if (!StringUtils.isEmpty(companyInfo.getPicId())) {
					PicInfo picInfo = picInfoDao.single(companyInfo.getPicId());
					if (picInfo != null) {
						cardInfoVo.setPicUrl(picInfo.getUrl());
					}
				}
				list.add(cardInfoVo);
			}
		}
		return list;
	}

}
